﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WCFContracts;
using TrainingWorkshop.IDAL;
using TrainingWorkshop.Model;

namespace WCFServices
{
    /// <summary>
    /// Author:Sissi-Zeng
    /// Date:2012-8-28 20:00
    /// Class ProjectBService provides a set of services to client.
    /// In this part, ProjectBService implements IProjectService methods in CourseSearch,which is a service contract
    public partial class ProjectBService : IProjectBService
    {
       /// <summary>
       /// Generate Report of CourseList that meet the searching condition
       /// </summary>
       /// <param name="condition">Given Condition</param>
       /// <returns></returns>
        public List<CourseList> GenerateCourseReport(Condition condition)
        {
            List<CourseList> a = new List<CourseList>();
            //handle input
            if (condition.CourseName.Length == 0)
            {
                condition.CourseName = "";
            }
            if (condition.TeacherName.StartsWith("--"))
            {
                condition.TeacherName = "";
            }
            if (condition.LevelName.StartsWith("--"))
            {
                condition.LevelName = "";
            }

            //call Factory
            ICourseListRepository couseListRep = factory.CreateCourseListRepository();

            //get CourseList
            List<TrainingWorkshop.Model.CourseList> courseList = couseListRep.SelectAllCourses(condition);

            //handle display detail
            if (courseList != null)
            {
                foreach (TrainingWorkshop.Model.CourseList c in courseList)
                {
                    if (c.CourseStatus)
                    {
                        c.StatusDisplay = "Open";
                    }
                    else
                    {
                        c.StatusDisplay = "Close";
                    }

                }
            }
            return courseList;
            }
        }
    }

